package Zuo.alg1;

/**
 * @author 24岁没牵过女人的手
 * 日期：2023/9/11 21:52
 * 文件描述：
 */
public class SelectSort {
    public static void selectSort(int[] arr1){
        if(arr1 == null || arr1.length< 2){
            return;
        }
        for (int i = 0; i < arr1.length -1; i++) {
            int minIndex = i;
            for (int j = i + 1; j < arr1.length; j++) {
                minIndex = arr1[j] < arr1[minIndex] ? j : minIndex;
            }
            swap(arr1, i, minIndex);
        }
    }

    public static void swap(int[] arr, int i, int j){
        int temp = arr[i];
        arr[i] = arr[j];
        arr[j] = temp;
    }

    public static void main(String[] args) {
        int[] input = {1, 6, 4, 2};
        selectSort(input);
        for (int i : input) {
            System.out.println(i);
        }
    }
}
